<!--
 * @Author: wuyuxin
 * @Date: 2022-04-16 17:08:28
 * @LastEditors: wuyuxin
 * @LastEditTime: 2022-04-24 10:41:51
 * @Description: 
-->
<template>
  <div class="nav-header">
    <template v-if="isFold">
      <el-icon @click="handleFoldClick" class="fold-menu"><expand /></el-icon>
    </template>
    <template v-else-if="!isFold">
      <el-icon @click="handleFoldClick" class="fold-menu"><fold /></el-icon>
    </template>
    <div class="content">
      <Breadcrumb :breadList="breadList"></Breadcrumb>
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
import UserInfo from './user-info.vue'
import Breadcrumb from '@/base-ui/breadcrumb/src/breadcrumb.vue'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
import { pathMapToMenusForBreadcrumb } from '@/utils/map-menus'

export default defineComponent({
  components: {
    UserInfo,
    Breadcrumb
  },
  emits: ['foldChange'],
  setup(props, { emit }) {
    const isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }
    const store = useStore()
    const userMenus = computed(() => store.state.loginModule.userMenus)
    const breadList = computed(() => {
      const route = useRoute()
      const path = route.path
      const useBreadList = pathMapToMenusForBreadcrumb(userMenus.value, path)
      return useBreadList
    })

    return {
      isFold,
      breadList,
      handleFoldClick
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;

  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
